package view.plugin
{
	//飘动的文字
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	
	import flash3.framework.Singleton;
	import global.Define;
	import libs.tweener.Tweener;
	import global.Resource;
	
	public class FloatText extends Sprite
	{
		private var msObj:MovieClip = null;
		public function FloatText():void
		{
			msObj = Resource.i.getMovieClip("common", "FloatMessage");
			msObj.mouseEnabled = false;
			msObj.txtMessage.mouseEnabled = false;
			msObj.txtMessage.text = "";
			msObj.addEventListener(Event.ADDED_TO_STAGE, onAddToStage);
			addChild(msObj);
		}
		private function onAddToStage(evt:Event):void
		{
			this.visible = false;
			this.mouseEnabled = false;
			msObj.removeEventListener(Event.ADDED_TO_STAGE, onAddToStage);
			msObj.x = (Define.SCREEN_WIDTH - msObj.width)/2;
			msObj.y = (Define.SCREEN_HEIGHT - msObj.height) / 2 + 28;
		}
		public function start(message:String) : void
		{
			this.visible = true;
			msObj.txtMessage.text = message;
			
			msObj.y = (stage.height - msObj.height) / 2 + 28;
			msObj.alpha = 0;
			msObj.visible = true;
			
			Tweener.addTween(msObj, {alpha:1, y:(stage.height - msObj.height) / 2 - 28, time:2.0, onComplete:onMoveComplete});
		}
		
		private function onMoveComplete():void
		{
			this.visible = false;
			msObj.visible = false;
		}
		
		static public function get i():FloatText
		{
			return Singleton.getInstanceOrCreate(FloatText) as FloatText;
		}
	}
}